#import "OmMineVC.h"
#import "OmDestinyVC.h"
#import "OmMineVCButtonsView.h"
#import "OmMineVCUserInformationView.h"
#import "PrivatePhotosViewController.h"
#import "OmMineVCCardView.h"
#import "FansBaseViewController.h"
#import "OmUploadMomentsVC.h"
#import "OmSettingVC.h"
#import "OmPersonalSettingVC.h"
#import "OmGetGoldVC.h"
#import "OmVisitorVC.h"
#import "OmJoinMemberVC.h"
#import "OmMomentsVC.h"
#import "RootWebViewController.h"
#import "UserApiGetUserPageInfoModel.h"
#import "OmGiftsListVC.h"
@interface OmMineVC ()
@property (nonatomic, strong) OmMineVCUserInformationView *userInformationView;
@property (nonatomic, strong) OmMineVCCardView *cardView;
@property (nonatomic, strong) OmMineVCButtonsView *buttonsView;
@end
@implementation OmMineVC
#pragma mark - Event
- (void)refreshSelf {
    [self.userInformationView.headImageView sd_setImageWithURL:[NSURL URLWithString:curUser.avatar]];
    self.userInformationView.nameLabel.text = curUser.user_nickname;
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"user_api" A:@"get_user_page_info"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"to_user_id"] = curUser.id;
    [CYNET POST:url parameters:param responseCache:^(id responseObject) {
    } success:^(id responseObject) {
        UserApiGetUserPageInfoModel *model = [UserApiGetUserPageInfoModel mj_objectWithKeyValues:responseObject];
        self.userInformationView.onlineLabel.text = ASLocalizedString(@"在线");
        self.userInformationView.ageLabel.text = [NSString stringWithFormat:@"%ld%@", model.age, ASLocalizedString(@"岁")];
        if (model.blue) {
            self.userInformationView.memberImageView.image = IMAGE_NAMED(@"OmBlueDiamond");
        }else if (model.crown) {
            self.userInformationView.memberImageView.image = IMAGE_NAMED(@"OmKingHat");
        }else {
            self.userInformationView.memberImageView.image = nil;
        }
    } failure:^(NSString *error) {
        if(StrValid(error))
            [MBProgressHUD showTopTipMessage:error];
    } hasCache:NO];
}
- (void)onPhotosButtonTap {
    PrivatePhotosViewController *vc = [[PrivatePhotosViewController alloc] init];
    vc.touid = curUser.id;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)onMyFollowButtonTap {
    FansBaseViewController *vc = [[FansBaseViewController alloc] init];
    vc.type = CYFansTypeAttr;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)onDestinyButtonTap {
    OmDestinyVC *vc = [[OmDestinyVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)onVisitorButtonTap {
    OmVisitorVC *vc = [[OmVisitorVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)onGetGoldButtonTap {
    OmGetGoldVC *vc = [[OmGetGoldVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)onJoinMemberButtonTap {
    OmJoinMemberVC *vc = [[OmJoinMemberVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)onSettingButtonTap {
    OmSettingVC *vc = [[OmSettingVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)goPersonalSetting {
    OmPersonalSettingVC *vc = [[OmPersonalSettingVC alloc] init];
    vc.ID = curUser.id;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)onGiftsButtonTap {
    OmGiftsListVC *vc = [[OmGiftsListVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)onMomentsButtonTap {
    OmMomentsVC *vc = [[OmMomentsVC alloc] init];
    vc.toUserID = curUser.id;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)onDailiShangTap {
    RootWebViewController *vc = [[RootWebViewController alloc] init];
    vc.url = [NSString stringWithFormat:@"http://www.omimorechat.com/mapi/public/index.php/api/invitation_api/index?uid=%@&token=%@", curUser.id, curUser.token];
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - ConstructionScript
- (void)configSelf {
    [self setHiddenForTabBar:NO navigationBar:YES];
    self.view.backgroundColor = [UIColor whiteColor];
}
- (void)allocateComponents {
    self.userInformationView = [[OmMineVCUserInformationView alloc] init];
    UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goPersonalSetting)];
    [self.userInformationView addGestureRecognizer:recognizer];
    [self.view addSubview:self.userInformationView];
    self.cardView = [[OmMineVCCardView alloc] init];
    self.cardView.photosButton.fp_addTargetActionForControlEvents(self, @selector(onPhotosButtonTap), UIControlEventTouchUpInside);
    self.cardView.momentsButton.fp_addTargetActionForControlEvents(self, @selector(onMomentsButtonTap), UIControlEventTouchUpInside);
    self.cardView.giftsButton.fp_addTargetActionForControlEvents(self, @selector(onGiftsButtonTap), UIControlEventTouchUpInside);
    [self.view addSubview:self.cardView];
    NSMutableArray *settings = [NSMutableArray arrayWithArray:@[@{@"title" : ASLocalizedString(@"我的关注"),
                                                                  @"selector" : @"onMyFollowButtonTap"
                                                                  },
                                                                @{@"title" : ASLocalizedString(@"缘分记录"),
                                                                  @"selector" : @"onDestinyButtonTap"
                                                                  },
                                                                @{@"title" : ASLocalizedString(@"我的访客"),
                                                                  @"selector" : @"onVisitorButtonTap"
                                                                  },
                                                                @{@"title" : ASLocalizedString(@"获取金币"),
                                                                  @"selector" : @"onGetGoldButtonTap"
                                                                  },
                                                                @{@"title" : ASLocalizedString(@"开通会员"),
                                                                  @"selector" : @"onJoinMemberButtonTap"
                                                                  },
                                                                @{@"title" : ASLocalizedString(@"设置"),
                                                                  @"selector" : @"onSettingButtonTap"
                                                                  }]];
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DaiLiQuanXian"]) {
        [settings addObject:@{@"title" : ASLocalizedString(@"代理商"),
                              @"selector" : @"onDailiShangTap"
                              }];
    }
    self.buttonsView = [[OmMineVCButtonsView alloc] initWithSettings:settings];
    [self.view addSubview:self.buttonsView];
}
- (void)layoutComponents {
    [self.userInformationView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.view);
    }];
    [self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(RPX(170));
        make.centerX.equalTo(self.view);
    }];
    [self.buttonsView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.cardView.mas_bottom).offset(RPX(15));
        make.left.equalTo(self.view);
    }];
}
@end
